package com.ansion.utils;

import android.text.TextUtils;

import com.ansion.log.VLog;

import java.util.Locale;

public class LanguageSettingHelper {

    private static final String TAG = "LanguageSettingHelper";

    private final String PREFENCE_LANGUAGE = "app_language";
    private final String PREFENCE_SYS_CHANGE = "prefence_sys_change";
    private final String LANGUAGE_DEFAULT = "en";

    private static LanguageSettingHelper helper;

    private LanguageSettingHelper(){
    }

    public synchronized static LanguageSettingHelper getInstance(){
        if(helper == null){
            synchronized (LanguageSettingHelper.class){
                if(helper == null){
                    helper = new LanguageSettingHelper();
                }
            }
        }

        return helper;
    }



    /**
     * get the app language setting
     * @return ar en ru pt es etc...
     */
    public static String getAppLanguage() {
    	
    	String sysLanguage = getSysDefaultLanguage();
    	return TextUtils.isEmpty(sysLanguage)?Locale.ENGLISH.getLanguage():sysLanguage;
    }

    public Locale getTimeLocale() {
        Locale locale = Locale.getDefault();
        if (null != locale) {
            return locale;
        }

        return Locale.ENGLISH;
    }
    



    private static String getSysDefaultLanguage() {
        Locale locale = Locale.getDefault();
        VLog.d(TAG, "sys locale = " + locale);
        if (locale != null) {
            return locale.getLanguage();
        }
        return null;
    }


    
    /**
     * 用于切换系统语言时用。
     * @param value
     */
    public void saveSysLanguageChange(boolean value){
//    	SharedPref.getInstance().putBoolean(PREFENCE_SYS_CHANGE, value);
    }
    
    /**
     * 获取当前是否改变了系统语言
     * @return
     */
//    public boolean hasSysLanguageChanged(){
//    	return BabaApplication.getSharedPref().getBoolean(PREFENCE_SYS_CHANGE, false);
//    }

    /**
     * 判断当前是否是阿拉伯语
     * @return
     */
    public  static boolean isArLanguage() {
        String language = getAppLanguage();
        return ("ar".equals(language));
    }
}
